package com.wewins.fota.bean.po;

import lombok.Data;
import org.springframework.util.StringUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Positive;
import javax.validation.constraints.Size;

@Data
public class PkgVersion {
    private int id;

    @Size(min = 2, max = 64, message = "产品名称长度[2,64]")
    private String product;

    @Size(min = 2, max = 64, message = "产品版本长度[2,64]")
    private String version;

    private String flag;

    @NotBlank
    private String uri;

    private long createTime;

    private long updateTime;

    @Positive
    private long releaseTime;

    private int size;

    private String sizeText;

    private String description;

    private String remark;

    public String constructFileCacheKey() {
        return uri.split("/download/")[1].replace("/", ":");
    }

    public PkgVersion refreshUser(String username) {
        this.remark = (StringUtils.isEmpty(this.remark) ? "" : this.remark) + "; owner:" + username;
        return this;
    }
}
